# -*- coding: utf-8 -*-
# @author: wch
# @file: warpAffine.py
# @time: 2023/2/9 16:55

# warpAffine(src,M,dsize,flags,mode,value) 仿射变换是缩放，旋转和平移
# src 路径
# M：变化矩阵
# dsize 变换后的大小
# flag ：与resize中的插值算法一直
# mode: 边界外推法 默认
# value:填充边界的值 默认

import cv2
import numpy as np

# 图像的平移，其变化矩阵是2*3的矩阵
# img = cv2.imread(r"E:\code\opencv\media\2.jpg")
# h, w, ch = img.shape
# M = np.float32([[1, 0, 100], [0, 1, 100]])
# new = cv2.warpAffine(img, M, (w, h))
# cv2.imshow("img", img)
# cv2.imshow("new", new)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

# M 变换矩阵的生成
# getRotationMatrix2D(center,angle,scale)
# center
# angle 角度(逆时针旋转）
# scle 缩放比例
img = cv2.imread(r"E:\code\opencv\media\2.jpg")
h, w, ch = img.shape
# M = cv2.getRotationMatrix2D((100,100),15,1.0)
M = cv2.getRotationMatrix2D((w/2,h/2),15,0.3)
new = cv2.warpAffine(img, M, (w, h))
cv2.imshow("img", img)
cv2.imshow("new", new)
cv2.waitKey(0)
cv2.destroyAllWindows()

# getAffineTransform(src,dst)
# src 原地址
# dst 变化后地址
M =cv2.getAffineTransform()